#!/bin/bash

download_dir=$1
url=$2

file_name=$(basename "$url")
file_size=$(wget --spider $url 2>&1 | grep Length | cut -d' ' -f2)

for i in {1..600}
do
  download_size=$(du -b $download_dir/$file_name | cut -f1)
  progress=$((100 * download_size / file_size))
  echo $progress > /tmp/download_progress.txt
  if (( $progress == 100 )); then
    break
  fi
  sleep 1
done

